﻿/**
* ...
* @author Fabien ANTOINE
*/

package xul.elem;

import Xml;

class XulElement
{
	var __childs:Array<XulElement>;
	
	public function new( ?o:Dynamic )
	{
		__childs = new Array();
		
		// Get class fields
		var fields:Hash<String> = new Hash();
		for( a in Type.getInstanceFields( Type.getClass( this ) ) ) fields.set( a, a );
		
		// Save contructor datas
		if( o != null )
			for( i in Reflect.fields( o ) )
				if( fields.exists( i ) && !Reflect.isFunction( Reflect.field( this, i ) ) )
					Reflect.setField( this, i, Reflect.field( o, i ) );
	}
	
	//{ Methods --------------------------------------------------------------------------
	
	public function addChild( child:XulElement ):Void
	{
		__childs.push( child );
	}
	
	public function getChilds():Array<XulElement>
	{
		return __childs;
	}
	
	public function hasChildNodes():Bool
	{
		return ( __childs.length > 0 );
	}
	
	public function insertBefore( newChild:XulElement, refChild:XulElement ):Void
	{
		var i = 0;
		while( i < __childs.length && __childs[ i ] != refChild ) i++;
		if( i < __childs.length ) __childs.insert( i, newChild );
	}
	
	public function removeChild( child:XulElement ):Void
	{
		__childs.remove( child );
	}
	
	public function replaceChild( child:XulElement, oldChild:XulElement ):Void
	{
		var i = 0;
		while( i < __childs.length && __childs[ i ] != oldChild ) i++;
		if( i < __childs.length )
		{
			__childs.splice( i, 1 );
			__childs.insert( i, child );
		}
	}
	
	//} --------------------------------------------------------------------------------
	
	
	public var align:Null<AlignType>;
	public var allowevents:Null<Bool>;
	public var allownegativeassertions:Null<Bool>;
	public var className:Null<String>;
	public var coalesceduplicatearcs:Null<Bool>;
	public var collapsed:Null<Bool>;
	public var container:Null<Bool>;
	public var containment:Null<String>; // URI of an RDF predicate
	public var context:Null<String>;
	public var contextmenu:Null<String>;
	public var datasources:Null<String>;
	public var dir:Null<DirType>;
	public var empty:Null<Bool>;
	public var equalsize:Null<TimeType>;
	public var flags:Null<FlagsType>;
	public var flex:Null<Int>;
	public var height:Null<Int>;
	public var hidden:Null<Bool>;
	public var id:Null<String>;
	public var insertafter:Null<String>;
	public var insertbefore:Null<String>;
	public var left:Null<Int>;
	public var maxheight:Null<Int>;
	public var maxwidth:Null<Int>;
	public var menu:Null<String>;
	public var minheight:Null<Int>;
	public var minwidth:Null<Int>;
	public var mousethrough:Null<TimeType>;
	public var observes:Null<String>;
	public var ordinal:Null<Int>;
	public var orient:Null<OrientationType>;
	public var pack:Null<AlignType>;
	public var persist:Null<String>;
	public var popup:Null<String>;
	public var position:Null<Int>;
	public var preference_editable:Null<Bool>;
	public var querytype:Null<String>;
	public var ref:Null<String>; // URI of an RDF resource
	public var removeelement:Null<String>;
	public var sortDirection:Null<DirectionType>;
	public var sortResource:Null<String>; // URI of an RDF resource
	public var sortResource2:Null<String>; // URI of an RDF resource
	public var statustext:Null<String>;
	public var style:Null<String>;
	public var template:Null<String>;
	public var tooltip:Null<String>;
	public var tooltiptext:Null<String>;
	public var top:Null<Int>;
	public var uri:Null<String>;
	public var wait_cursor:Null<Bool>;
	public var width:Null<Int>;
	
	public var oncommand:Null<String>;
}
/*
typedef Assign = { > XulElement,
	public var expr:Null<String>;
	public var varName:Null<String>;
}*/

// -------------------------------------------------------

enum AlignType
{
	start;
	center;
	end;
	baseline;
	stretch;
	none;
	
	// Deprecated
	left;
	right;
}

enum ContentType
{
	content;
	content_primary;
	content_targetable;
}

enum DialogType
{
	accept;
	cancel;
	help;
	disclosure;
}

enum DirectionType
{
	ascending;
    descending;
    natural;
}

enum DirType
{
	normal;
	reverse;
	inherit;
}

enum FlagsType
{
	dont_test_empty;
	dont_build_content;
}
/*
enum LoadFlags
{
	LOAD_FLAGS_IS_REFRESH;
	LOAD_FLAGS_IS_LINK;
	LOAD_FLAGS_BYPASS_HISTORY;
	LOAD_FLAGS_REPLACE_HISTORY;
	
	LOAD_FLAGS_NONE;
	LOAD_FLAGS_BYPASS_CACHE;
	LOAD_FLAGS_BYPASS_PROXY;
	LOAD_FLAGS_CHARSET_CHANGE;
}
*/
enum OrientationType
{
	vertical;
	horizontal;
}

enum TimeType
{
	always;
	never;
}

enum WindowState
{
	maximized;
	minimized;
	normal;
}